#ifndef DBCONTROLER_H
#define DBCONTROLER_H
#include <QSqlDatabase>
#include <QObject>
#include <QMutex>
#include "protocol.h"
#include <QVariant>
#include <memory>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
class DBControler : public QObject
{
    Q_OBJECT
public:
    explicit DBControler(QObject *parent = nullptr);

    ~DBControler();

    static std::shared_ptr<DBControler> get_instance();

    int _connect();

    int _config();

    int _disconnect();

    bool _RegisterUser(const char* _UserName,const char* _Pwd);

    bool _LoginUser(const char* _UserName,const char* _Pwd,QMap<QString,QVariant>&GetInfo);

    bool _UpDateOnlineStatus(const char* _UserName,int _Status);

    bool _DownloadUpdate(const char * _UserName);

    bool SearchOnline(const char * _UserName,QList<QPair<QString, QString>>&info);

    QList<QPair<QString,QString>> _AllNetScanUser(const char *_UserName);

    bool _SetFriendRequestInfo(QString SenderName,QString RecvName,int status);

    QList<QMap<QString,QVariant>> _PullFriendRequest(QString UserName);

    bool _MakeFriend(QString User1,QString User2,int Status,QString Info);

    bool UpfriendRequestTableStatus(QString User1,QString User2,int Status);

    bool getUserEtc(QString User,QString & Value);

    bool _isFriend(QString User1,QString User2);

    bool _PullFriendList(QString User,QJsonArray & Info);


    static void distroy_instance();
private:
    static std::shared_ptr<DBControler> DBMaster;

    QSqlDatabase db;

    static QMutex mutex;



signals:

};

#endif // DBCONTROLER_H
